package com.youfan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.youfan.entity.ProductattributeValue;
import com.youfan.mapper.ProductAttrValueMapper;
import com.youfan.page.CommonPage;
import com.youfan.service.ProductAttrValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
public class ProductattrValueServiceImpl extends ServiceImpl<ProductAttrValueMapper, ProductattributeValue> implements ProductAttrValueService {

    @Autowired
    private ProductAttrValueMapper productAttrValueMapper;




    @Override
    public int insertOne(ProductattributeValue youfanproductattributeValue) {
        youfanproductattributeValue.setCreateTime(new Date());
        return productAttrValueMapper.insert(youfanproductattributeValue);
    }

    @Override
    public CommonPage<ProductattributeValue> queryByCondtion(ProductattributeValue youfanproductattributeValue) {
        PageHelper.startPage(youfanproductattributeValue.getPageNum(),youfanproductattributeValue.getPageSize());
        QueryWrapper queryWrapper = new QueryWrapper();
        if(youfanproductattributeValue.getProductid()!=null){
            queryWrapper.eq("productid", youfanproductattributeValue.getProductid());
        }

        if(youfanproductattributeValue.getAttributeDictId()!=null){
            queryWrapper.eq("attribute_dict_id",youfanproductattributeValue.getAttributeDictId());
        }


        List<ProductattributeValue> list = productAttrValueMapper.selectList(queryWrapper);


        return CommonPage.restPage(list);
    }

    @Override
    public ProductattributeValue findByid(ProductattributeValue youfanproductattributeValue) {
        return productAttrValueMapper.selectById(youfanproductattributeValue.getId());
    }

    @Override
    public int updateOne(ProductattributeValue youfanproductattributeValue) {
        return productAttrValueMapper.updateById(youfanproductattributeValue);
    }
}
